<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>

    <title>微信支付样例-支付</title>

</head>
<body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<br/>
<font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span>钱</b></font><br/><br/>
<div align="center">
    <button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" type="button" onclick="callpay()" >立即支付</button>
</div>
<div id="pay" value="">123</div>
<script type="text/javascript">
    $(function () {
        var bb=unifiedorder();
       // console.log(aa.responseText);

        //获取支付参数
        // GetPayConfig();

        //  var test=$('<div/>').html('{$jsApiParameters}').text()
        // var aa= JSON.parse(test)
        //
        //  console.log( JSON.parse(test))

    })
    function unifiedorder() {
      var   bb=   $.ajax({
            type: "post",
            url: 'http://124.70.177.101:6001/api/order/ordersPay',
            data: {
                pay_type:1,
                order_number:'0806505452549766',
                // openid: 'oitr0wA-5px7tWfFr-HZRlN4Pjlk',
                price: 1000,//微商城预付款场景编号
                body: '微商城汽车预付',//场景名称
            },
            dataType: "json",
            async: false,
            success: function (response) {
                var data = response.return_msg;
                console.log(data);


                return data
                //window._payJson = data;
                // if (response.code == 200) {


                // }
                // else {
                //     alert("统一下单:" + response.msg);
                // }
            }
        });

        $('#pay').html(bb)
        // return bb
    }

    //调用微信JS api 支付
    function jsApiCall()
    {
        console.log(11);


        // var test=$('#pay').html()
        // console.log(test);
        var test = {
            appId: "wxbd286076bd81f5d5",
            nonceStr: "xKRwgohkfspkFKkg",
            order_number: "0806505452549766",
            package: "prepay_id=wx15094049127801f9d91ded8ea37a040000",
            paySign: "3A12B200AA96B53633C93EC9FBF6A09E",
            signType: "MD5",
            timeStamp: "1597455649",
            total_fee: 1
        }
        // var aa= JSON.parse(test).return_msg
        var aa= test
        console.log(aa);
        // return false;
        WeixinJSBridge.invoke(

            'getBrandWCPayRequest', {
                'appId': aa.appId,
                'nonceStr': aa.nonceStr,
                'package': aa.package,
                'signType': aa.signType,
                'timeStamp': aa.timeStamp,
                'paySign': aa.paySign,
            },
            function(res){
                WeixinJSBridge.log(res.err_msg);
                alert(res.err_code+res.err_desc+res.err_msg);
            }
        );
    }

    function callpay()
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall();
        }
    }
</script>

</body>
</html>